<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  
  <title>JPA @OneToMany 关系 | gdme1320 的笔记</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="Table of Contents   单向@OneToMany关联 单向@OneToMany关联与@JoinColumn一起使用 双向关联 ManyToOne 单向关联      https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/    使用 @OneToM">
<meta property="og:type" content="article">
<meta property="og:title" content="JPA @OneToMany 关系">
<meta property="og:url" content="http://gdme1320.gitee.com/java/spring-jpa/one-to-many/index.html">
<meta property="og:site_name" content="gdme1320 的笔记">
<meta property="og:description" content="Table of Contents   单向@OneToMany关联 单向@OneToMany关联与@JoinColumn一起使用 双向关联 ManyToOne 单向关联      https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/    使用 @OneToM">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2022-03-23T09:59:36.787Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JPA @OneToMany 关系">
<meta name="twitter:description" content="Table of Contents   单向@OneToMany关联 单向@OneToMany关联与@JoinColumn一起使用 双向关联 ManyToOne 单向关联      https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/    使用 @OneToM">
  
    <link rel="alternate" href="/atom.xml" title="gdme1320 的笔记" type="application/atom+xml">
  
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" integrity="sha384-XdYbMnZ/QjLh6iI4ogqCTaIjrFk87ip+ekIjefZch0Y+PvJ8CDYtEs1ipDmPorQ+" crossorigin="anonymous">

  <link rel="stylesheet" href="/css/styles.css">
  <link rel="stylesheet" href="/css/docs.min.css">
  

</head>
</html>
<body>
  <nav class="navbar navbar-inverse">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="main-menu-navbar">
      <ul class="nav navbar-nav">
        
          <li><a class href="/index.html">Home</a></li>
        
          <li><a class href="/archives/">Archives</a></li>
        
      </ul>

      <!--
      <ul class="nav navbar-nav navbar-right">
        
          <li><a href="/atom.xml" title="RSS Feed"><i class="fa fa-rss"></i></a></li>
        
      </ul>
      -->
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

  <div class="container bs-docs-container">
  
    <div class="row">
        <div class="col-sm-8 blog-main">
          <article id="post-java/spring-jpa/one-to-many" class="article article-type-post" itemscope itemprop="blogPost">

  <header class="article-header">
    
  
    <h1 class="article-title" itemprop="name">
      JPA @OneToMany 关系
    </h1>
  


  </header>

  <div class="article-meta">
    <div class="article-datetime">
  <a href="/java/spring-jpa/one-to-many/" class="article-date"><time datetime="2020-12-28T16:00:00.000Z" itemprop="datePublished">2020-12-29</time></a>
</div>

    
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/java/">java</a> / <a class="article-category-link" href="/categories/java/spring-jpa/">spring-jpa</a>
  </div>


  </div>
  <div class="article-inner">

    <div class="article-entry" itemprop="articleBody">
      
        
<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org3e7af71">单向@OneToMany关联</a></li>
<li><a href="#orgf794b32">单向@OneToMany关联与@JoinColumn一起使用</a></li>
<li><a href="#org11d7ddd">双向关联</a></li>
<li><a href="#org86d279e">ManyToOne 单向关联</a></li>
</ul>
</div>
</div>
<blockquote>
<p>
<a href="https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/" target="_blank" rel="noopener">https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/</a>
</p>
</blockquote>
<p>
使用 @OneToMany 能够很方便地进行简单的Join查询而不用编写join sql语句。
</p>
<p>
假设一个数据库关系：
</p>
<table border="2" cellpadding="6" cellspacing="0" frame="hsides" rules="groups">
<colgroup>
<col class="org-left">
<col class="org-left">
</colgroup>
<thead>
<tr>
<th class="org-left" scope="col">post</th>
<th class="org-left" scope="col"> </th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">id</td>
<td class="org-left">int</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="org-left">title</td>
<td class="org-left">varchar</td>
</tr>
</tbody>
</table>
<table border="2" cellpadding="6" cellspacing="0" frame="hsides" rules="groups">
<colgroup>
<col class="org-left">
<col class="org-left">
</colgroup>
<thead>
<tr>
<th class="org-left" scope="col">post_comment</th>
<th class="org-left" scope="col"> </th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">id</td>
<td class="org-left">id</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="org-left">review</td>
<td class="org-left">text</td>
</tr>
<tr>
<td class="org-left">post_id</td>
<td class="org-left">int</td>
</tr>
</tbody>
</table>
<div class="outline-2" id="outline-container-org3e7af71">
<h2 id="org3e7af71">单向@OneToMany关联</h2>
<div class="outline-text-2" id="text-org3e7af71">
<div class="org-src-container">
<pre class="src src-java"><span style="font-weight: bold; text-decoration: underline;">@Entity</span>(name = <span style="font-style: italic;">"Post"</span>)
<span style="font-weight: bold; text-decoration: underline;">@Table</span>(name = <span style="font-style: italic;">"post"</span>)
<span style="font-weight: bold;">public</span> <span style="font-weight: bold;">class</span> <span style="font-weight: bold; text-decoration: underline;">Post</span> {

    <span style="font-weight: bold; text-decoration: underline;">@Id</span>
    <span style="font-weight: bold; text-decoration: underline;">@GeneratedValue</span>
    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">Long</span> <span style="font-weight: bold; font-style: italic;">id</span>;

    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">String</span> <span style="font-weight: bold; font-style: italic;">title</span>;

    <span style="font-weight: bold; text-decoration: underline;">@OneToMany</span>(
        cascade = <span style="font-weight: bold; text-decoration: underline;">CascadeType</span>.ALL,
        orphanRemoval = <span style="font-weight: bold; text-decoration: underline;">true</span>
    )
    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">List</span>&lt;<span style="font-weight: bold; text-decoration: underline;">PostComment</span>&gt; <span style="font-weight: bold; font-style: italic;">comments</span> = <span style="font-weight: bold;">new</span> <span style="font-weight: bold; text-decoration: underline;">ArrayList</span>&lt;&gt;();

    <span style="font-weight: bold; font-style: italic;">//</span><span style="font-weight: bold; font-style: italic;">Constructors, getters and setters removed for brevity</span>
}

<span style="font-weight: bold; text-decoration: underline;">@Entity</span>(name = <span style="font-style: italic;">"PostComment"</span>)
<span style="font-weight: bold; text-decoration: underline;">@Table</span>(name = <span style="font-style: italic;">"post_comment"</span>)
<span style="font-weight: bold;">public</span> <span style="font-weight: bold;">class</span> <span style="font-weight: bold; text-decoration: underline;">PostComment</span> {

    <span style="font-weight: bold; text-decoration: underline;">@Id</span>
    <span style="font-weight: bold; text-decoration: underline;">@GeneratedValue</span>
    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">Long</span> <span style="font-weight: bold; font-style: italic;">id</span>;

    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">String</span> <span style="font-weight: bold; font-style: italic;">review</span>;

    <span style="font-weight: bold; font-style: italic;">//</span><span style="font-weight: bold; font-style: italic;">Constructors, getters and setters removed for brevity</span>
}
</pre>
</div>
<p>
创建Post并添加三个评论，
</p>
<div class="org-src-container">
<pre class="src src-java"><span style="font-weight: bold; text-decoration: underline;">Post</span> <span style="font-weight: bold; font-style: italic;">post</span> = <span style="font-weight: bold;">new</span> <span style="font-weight: bold; text-decoration: underline;">Post</span>(<span style="font-style: italic;">"First post"</span>);

post.getComments().add(
    <span style="font-weight: bold;">new</span> <span style="font-weight: bold; text-decoration: underline;">PostComment</span>(<span style="font-style: italic;">"My first review"</span>)
);
post.getComments().add(
    <span style="font-weight: bold;">new</span> <span style="font-weight: bold; text-decoration: underline;">PostComment</span>(<span style="font-style: italic;">"My second review"</span>)
);
post.getComments().add(
    <span style="font-weight: bold;">new</span> <span style="font-weight: bold; text-decoration: underline;">PostComment</span>(<span style="font-style: italic;">"My third review"</span>)
);

entityManager.persist(post);
</pre>
</div>
<p>
Hibernate生成的语句是
</p>
<div class="org-src-container">
<pre class="src src-sql">
# post
<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post (title, id)
<span style="font-weight: bold;">values</span> (<span style="font-style: italic;">'First post'</span>, 1)

# post_comment
<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post_comment (review, id)
<span style="font-weight: bold;">values</span> (<span style="font-style: italic;">'My first review'</span>, 2)

<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post_comment (review, id)
<span style="font-weight: bold;">values</span> (<span style="font-style: italic;">'My second review'</span>, 3)

<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post_comment (review, id)
<span style="font-weight: bold;">values</span> (<span style="font-style: italic;">'My third review'</span>, 4)

# Hibernate自动生成的中间表，即使是OneToMany，Hibernate也以多对多的方式存储了这些记录，这样效率肯定是比较低的
<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post_post_comment (Post_id, comments_id)
<span style="font-weight: bold;">values</span> (1, 2)

<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post_post_comment (Post_id, comments_id)
<span style="font-weight: bold;">values</span> (1, 3)

<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post_post_comment (Post_id, comments_id)
<span style="font-weight: bold;">values</span> (1, 4)
</pre>
</div>
</div>
</div>
<div class="outline-2" id="outline-container-orgf794b32">
<h2 id="orgf794b32">单向@OneToMany关联与@JoinColumn一起使用</h2>
<div class="outline-text-2" id="text-orgf794b32">
<div class="org-src-container">
<pre class="src src-java"><span style="font-weight: bold; font-style: italic;">// </span><span style="font-weight: bold; font-style: italic;">修改Post.comments，添加@JoinColumn注解</span>
<span style="font-weight: bold; text-decoration: underline;">@OneToMany</span>(cascade = <span style="font-weight: bold; text-decoration: underline;">CascadeType</span>.ALL, orphanRemoval = <span style="font-weight: bold; text-decoration: underline;">true</span>)
<span style="font-weight: bold; font-style: italic;">// </span><span style="font-weight: bold; font-style: italic;">post_id为PostComment中的postId列名，不是字段名</span>
<span style="font-weight: bold; text-decoration: underline;">@JoinColumn</span>(name = <span style="font-style: italic;">"post_id"</span>)
<span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">List</span>&lt;<span style="font-weight: bold; text-decoration: underline;">PostComment</span>&gt; <span style="font-weight: bold; font-style: italic;">comments</span> = <span style="font-weight: bold;">new</span> <span style="font-weight: bold; text-decoration: underline;">ArrayList</span>&lt;&gt;();
</pre>
</div>
<p>
执行上面的添加，生成的SQL语句：
</p>
<div class="org-src-container">
<pre class="src src-sql"><span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post (title, id)
<span style="font-weight: bold;">values</span> (<span style="font-style: italic;">'First post'</span>, 1)

<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post_comment (review, id)
<span style="font-weight: bold;">values</span> (<span style="font-style: italic;">'My first review'</span>, 2)

<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post_comment (review, id)
<span style="font-weight: bold;">values</span> (<span style="font-style: italic;">'My second review'</span>, 3)

<span style="font-weight: bold;">insert</span> <span style="font-weight: bold;">into</span> post_comment (review, id)
<span style="font-weight: bold;">values</span> (<span style="font-style: italic;">'My third review'</span>, 4)

# 生成的 <span style="font-weight: bold;">update</span>，
<span style="font-weight: bold;">update</span> post_comment <span style="font-weight: bold;">set</span> post_id = 1 <span style="font-weight: bold;">where</span> id = 2

<span style="font-weight: bold;">update</span> post_comment <span style="font-weight: bold;">set</span> post_id = 1 <span style="font-weight: bold;">where</span> id =  3

<span style="font-weight: bold;">update</span> post_comment <span style="font-weight: bold;">set</span> post_id = 1 <span style="font-weight: bold;">where</span> id =  4
</pre>
</div>
<p>
查看 <a href="https://vladmihalcea.com/hibernate-facts-knowing-flush-operations-order-matters/" target="_blank" rel="noopener">原理</a>
</p>
<p>
这种方式，如果执行删除：
</p>
<div class="org-src-container">
<pre class="src src-java">post.getComments().remove(0);
</pre>
</div>
<p>
生成的SQL语句：
</p>
<div class="org-src-container">
<pre class="src src-sql"><span style="font-weight: bold;">update</span> post_comment <span style="font-weight: bold;">set</span> post_id = <span style="font-weight: bold;">null</span> <span style="font-weight: bold;">where</span> post_id = 1 <span style="font-weight: bold;">and</span> id = 2

<span style="font-weight: bold;">delete</span> <span style="font-weight: bold;">from</span> post_comment <span style="font-weight: bold;">where</span> id=2
</pre>
</div>
</div>
</div>
<div class="outline-2" id="outline-container-org11d7ddd">
<h2 id="org11d7ddd">双向关联</h2>
<div class="outline-text-2" id="text-org11d7ddd">
<div class="org-src-container">
<pre class="src src-java"><span style="font-weight: bold; text-decoration: underline;">@Entity</span>(name = <span style="font-style: italic;">"Post"</span>)
<span style="font-weight: bold; text-decoration: underline;">@Table</span>(name = <span style="font-style: italic;">"post"</span>)
<span style="font-weight: bold;">public</span> <span style="font-weight: bold;">class</span> <span style="font-weight: bold; text-decoration: underline;">Post</span> {

    <span style="font-weight: bold; text-decoration: underline;">@Id</span>
    <span style="font-weight: bold; text-decoration: underline;">@GeneratedValue</span>
    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">Long</span> <span style="font-weight: bold; font-style: italic;">id</span>;

    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">String</span> <span style="font-weight: bold; font-style: italic;">title</span>;

    <span style="font-weight: bold; text-decoration: underline;">@OneToMany</span>(
        mappedBy = <span style="font-style: italic;">"post"</span>,
        cascade = <span style="font-weight: bold; text-decoration: underline;">CascadeType</span>.ALL,
        orphanRemoval = <span style="font-weight: bold; text-decoration: underline;">true</span>
    )
    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">List</span>&lt;<span style="font-weight: bold; text-decoration: underline;">PostComment</span>&gt; <span style="font-weight: bold; font-style: italic;">comments</span> = <span style="font-weight: bold;">new</span> <span style="font-weight: bold; text-decoration: underline;">ArrayList</span>&lt;&gt;();

    <span style="font-weight: bold; font-style: italic;">//</span><span style="font-weight: bold; font-style: italic;">Constructors, getters and setters removed for brevity</span>

    <span style="font-weight: bold; font-style: italic;">// </span><span style="font-weight: bold; font-style: italic;">addComment, removeComment这几个方法，用于同步两个实体的关联。这样的方法每个这样双向关联的类都应该提供</span>

    <span style="font-weight: bold;">public</span> <span style="font-weight: bold; text-decoration: underline;">void</span> <span style="font-weight: bold;">addComment</span>(<span style="font-weight: bold; text-decoration: underline;">PostComment</span> <span style="font-weight: bold; font-style: italic;">comment</span>) {
        comments.add(comment);
        comment.setPost(<span style="font-weight: bold;">this</span>);
    }

    <span style="font-weight: bold;">public</span> <span style="font-weight: bold; text-decoration: underline;">void</span> <span style="font-weight: bold;">removeComment</span>(<span style="font-weight: bold; text-decoration: underline;">PostComment</span> <span style="font-weight: bold; font-style: italic;">comment</span>) {
        comments.remove(comment);
        comment.setPost(<span style="font-weight: bold; text-decoration: underline;">null</span>);
    }
}

<span style="font-weight: bold; text-decoration: underline;">@Entity</span>(name = <span style="font-style: italic;">"PostComment"</span>)
<span style="font-weight: bold; text-decoration: underline;">@Table</span>(name = <span style="font-style: italic;">"post_comment"</span>)
<span style="font-weight: bold;">public</span> <span style="font-weight: bold;">class</span> <span style="font-weight: bold; text-decoration: underline;">PostComment</span> {

    <span style="font-weight: bold; text-decoration: underline;">@Id</span>
    <span style="font-weight: bold; text-decoration: underline;">@GeneratedValue</span>
    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">Long</span> <span style="font-weight: bold; font-style: italic;">id</span>;

    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">String</span> <span style="font-weight: bold; font-style: italic;">review</span>;

    <span style="font-weight: bold; font-style: italic;">// </span><span style="font-weight: bold; font-style: italic;">注意FetchType，FetchType.EAGER在每次查询PostComment实体时都会join Post表，性能不好</span>
    <span style="font-weight: bold; text-decoration: underline;">@ManyToOne</span>(fetch = <span style="font-weight: bold; text-decoration: underline;">FetchType</span>.LAZY)
    <span style="font-weight: bold;">private</span> <span style="font-weight: bold; text-decoration: underline;">Post</span> <span style="font-weight: bold; font-style: italic;">post</span>;

    <span style="font-weight: bold; font-style: italic;">//</span><span style="font-weight: bold; font-style: italic;">Constructors, getters and setters removed for brevity</span>

    <span style="font-weight: bold; font-style: italic;">// </span><span style="font-weight: bold; font-style: italic;">重写的equals方法，通过id进行比较是否相同</span>
    <span style="font-weight: bold; text-decoration: underline;">@Override</span>
    <span style="font-weight: bold;">public</span> <span style="font-weight: bold; text-decoration: underline;">boolean</span> <span style="font-weight: bold;">equals</span>(<span style="font-weight: bold; text-decoration: underline;">Object</span> <span style="font-weight: bold; font-style: italic;">o</span>) {
        <span style="font-weight: bold;">if</span> (<span style="font-weight: bold;">this</span> == o) <span style="font-weight: bold;">return</span> <span style="font-weight: bold; text-decoration: underline;">true</span>;
        <span style="font-weight: bold;">if</span> (!(o <span style="font-weight: bold;">instanceof</span> PostComment )) <span style="font-weight: bold;">return</span> <span style="font-weight: bold; text-decoration: underline;">false</span>;
        <span style="font-weight: bold;">return</span> id != <span style="font-weight: bold; text-decoration: underline;">null</span> &amp;&amp; id.equals(((<span style="font-weight: bold; text-decoration: underline;">PostComment</span>) o).getId());
    }

    <span style="font-weight: bold; font-style: italic;">// </span><span style="font-weight: bold; font-style: italic;">重写的hashCode方法，</span>
    <span style="font-weight: bold; text-decoration: underline;">@Override</span>
    <span style="font-weight: bold;">public</span> <span style="font-weight: bold; text-decoration: underline;">int</span> <span style="font-weight: bold;">hashCode</span>() {
        <span style="font-weight: bold;">return</span> getClass().hashCode();
    }
}
</pre>
</div>
<p>
注意：
</p>
<ul class="org-ul">
<li>在每个Post这样双向关联的实体中都应该提供addComment，removeComment方法，否则会遇到 <a href="https://vladmihalcea.com/jpa-hibernate-synchronize-bidirectional-entity-associations/" target="_blank" rel="noopener">very subtle state propagation issues</a> 问题</li>
<li><a href="https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/" target="_blank" rel="noopener">为什么要重写equals hashCode</a></li>
</ul>
<p>
双向关联的实体，JPA生成的语句很正常没有上面那些额外的update
</p>
</div>
</div>
<div class="outline-2" id="outline-container-org86d279e">
<h2 id="org86d279e">ManyToOne 单向关联</h2>
<div class="outline-text-2" id="text-org86d279e">
<p>
仅在 PostComment 类上加 @ManyToOne 也是允许的，甚至很多场景只需要这个单向关联即满足需求。
</p>
<p>
查询某个Post的所有PostComment只需要下面的语句：
</p>
<div class="org-src-container">
<pre class="src src-jpql">select pc from PostComment pc where pc.post.id = :postId
</pre>
</div>
</div>
</div>
</div>
<div class="status" id="postamble">
<p class="date">Date: 2020-12-29</p>
<p class="author">Author: gdme1320</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer" target="_blank" rel="noopener">Validate</a></p>
</div>

      
    </div>

    
      

    

    <footer class="article-footer">
      <a data-url="http://gdme1320.gitee.com/java/spring-jpa/one-to-many/" data-id="cl13eo7mt00eshjv4yo2gcali" class="article-share-link">
        <i class="fa fa-share"></i> Share
      </a>
      
      

    </footer>
  </div>
  
    
<ul id="article-nav" class="nav nav-pills nav-justified">
  
  <li role="presentation">
    <a href="/linux/bash/" id="article-nav-older" class="article-nav-link-wrap">
      <i class="fa fa-chevron-left pull-left"></i>
      <span class="article-nav-link-title">Bash</span>
    </a>
  </li>
  
  
  <li role="presentation">
    <a href="/java/spring/useful-classes/" id="article-nav-newer" class="article-nav-link-wrap">
      <span class="article-nav-link-title">Spring中有用的类</span>
      <i class="fa fa-chevron-right pull-right"></i>
    </a>
  </li>
  
</ul>


  
</article>




        </div>
        <div class="col-sm-3 col-sm-offset-1 blog-sidebar">
          
  
  <div class="sidebar-module">
    <h4>Categories</h4>
    <ul class="sidebar-module-list"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/apps/">apps</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/architecture/">architecture</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/devops/">devops</a><span class="sidebar-module-list-count">10</span><ul class="sidebar-module-list-child"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/devops/kubectl/">kubectl</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/devops/kubernetes/">kubernetes</a><span class="sidebar-module-list-count">3</span></li></ul></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/dotnet/">dotnet</a><span class="sidebar-module-list-count">3</span><ul class="sidebar-module-list-child"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/dotnet/entityframework/">entityframework</a><span class="sidebar-module-list-count">1</span></li></ul></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/elasticsearch/">elasticsearch</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/emacs/">emacs</a><span class="sidebar-module-list-count">4</span><ul class="sidebar-module-list-child"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/emacs/org-mode/">org-mode</a><span class="sidebar-module-list-count">3</span></li></ul></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/git/">git</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/graphql/">graphql</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/groovy/">groovy</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/">java</a><span class="sidebar-module-list-count">52</span><ul class="sidebar-module-list-child"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/concurrent/">concurrent</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/jackson/">jackson</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/shiro/">shiro</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/spring/">spring</a><span class="sidebar-module-list-count">11</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/spring-amqp/">spring-amqp</a><span class="sidebar-module-list-count">5</span><ul class="sidebar-module-list-child"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/spring-amqp/spring-jpa/">spring-jpa</a><span class="sidebar-module-list-count">1</span></li></ul></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/spring-jpa/">spring-jpa</a><span class="sidebar-module-list-count">10</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/spring-security/">spring-security</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/thymeleaf/">thymeleaf</a><span class="sidebar-module-list-count">2</span><ul class="sidebar-module-list-child"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/java/thymeleaf/maven/">maven</a><span class="sidebar-module-list-count">1</span></li></ul></li></ul></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/jenkins/">jenkins</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/journal/">journal</a><span class="sidebar-module-list-count">7</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/js/">js</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/linux/">linux</a><span class="sidebar-module-list-count">35</span><ul class="sidebar-module-list-child"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/linux/kde/">kde</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/linux/kross/">kross</a><span class="sidebar-module-list-count">3</span><ul class="sidebar-module-list-child"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/linux/kross/ktorrent-scripts/">ktorrent-scripts</a><span class="sidebar-module-list-count">1</span></li></ul></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/linux/shell/">shell</a><span class="sidebar-module-list-count">6</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/linux/tcp/">tcp</a><span class="sidebar-module-list-count">1</span></li></ul></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/lisp/">lisp</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/mongodb/">mongodb</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/mssql/">mssql</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/mysql/">mysql</a><span class="sidebar-module-list-count">12</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/nginx/">nginx</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/node/">node</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/postgresql/">postgresql</a><span class="sidebar-module-list-count">2</span><ul class="sidebar-module-list-child"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/postgresql/client/">client</a><span class="sidebar-module-list-count">1</span></li></ul></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/python/">python</a><span class="sidebar-module-list-count">19</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/regex/">regex</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/rfc/">rfc</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/vim/">vim</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/windows/">windows</a><span class="sidebar-module-list-count">7</span></li></ul>
  </div>



  
  <div class="sidebar-module">
    <h4>Tags</h4>
    <ul class="sidebar-module-list"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/ReentrantLock/">ReentrantLock</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/nohup/">nohup</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/pandoc/">pandoc</a><span class="sidebar-module-list-count">1</span></li></ul>
  </div>



  
  <div class="sidebar-module">
    <h4>Tag Cloud</h4>
    <p class="tagcloud">
      <a href="/tags/ReentrantLock/" style="font-size: 10px;">ReentrantLock</a> <a href="/tags/nohup/" style="font-size: 10px;">nohup</a> <a href="/tags/pandoc/" style="font-size: 10px;">pandoc</a>
    </p>
  </div>


  
  <div class="sidebar-module">
    <h4>Archives</h4>
    <ul class="sidebar-module-list"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2919/06/">June 2919</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2022/03/">March 2022</a><span class="sidebar-module-list-count">58</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2022/01/">January 2022</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2021/11/">November 2021</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2021/10/">October 2021</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2021/04/">April 2021</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2021/03/">March 2021</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2021/02/">February 2021</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2021/01/">January 2021</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/12/">December 2020</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/11/">November 2020</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/10/">October 2020</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/09/">September 2020</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/07/">July 2020</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/06/">June 2020</a><span class="sidebar-module-list-count">10</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/04/">April 2020</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/03/">March 2020</a><span class="sidebar-module-list-count">8</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/02/">February 2020</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2020/01/">January 2020</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/12/">December 2019</a><span class="sidebar-module-list-count">7</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/11/">November 2019</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/10/">October 2019</a><span class="sidebar-module-list-count">11</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/09/">September 2019</a><span class="sidebar-module-list-count">6</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/08/">August 2019</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/07/">July 2019</a><span class="sidebar-module-list-count">10</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/06/">June 2019</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/05/">May 2019</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/04/">April 2019</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/03/">March 2019</a><span class="sidebar-module-list-count">8</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/02/">February 2019</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2019/01/">January 2019</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2018/11/">November 2018</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2018/10/">October 2018</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2018/08/">August 2018</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2018/07/">July 2018</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2018/06/">June 2018</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2018/03/">March 2018</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2017/07/">July 2017</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2017/06/">June 2017</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2017/04/">April 2017</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/05/">May 2015</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/1970/01/">January 1970</a><span class="sidebar-module-list-count">9</span></li></ul>
  </div>



  
  <div class="sidebar-module">
    <h4>Recents</h4>
    <ul class="sidebar-module-list">
      
        <li>
          <a href="/java/acessing-generic-types-at-runtime/">获取泛型类型</a>
        </li>
      
        <li>
          <a href="/linux/shell/bash_cgi/">Script for Shell Parsing Parameters</a>
        </li>
      
        <li>
          <a href="/linux/shell/shell-script/">Shell Script Getting Start</a>
        </li>
      
        <li>
          <a href="/linux/tcp/network-tcp-performance-turning-with-sysctl/">【翻译】Sysctl调节Linux网络性能</a>
        </li>
      
        <li>
          <a href="/java/concurrent/aqs-src/">AQS源码笔记</a>
        </li>
      
    </ul>
  </div>



        </div>
    </div>
  </div>
  <footer class="blog-footer">
  <div class="container">
    <div id="footer-info" class="inner">
      &copy; 2022 gdme1320<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

  

<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script> -->

<script src="/js/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>



<script src="/js/script.js"></script>

</body>
</html>
